#pragma once
#include "InfoM.h"
#include "VectorCache.h"
#include "conductivelayer.h"

class VertMagnDipole
{
	double	*MsArray;
	int		MsCount;
	
	int		TimesCount;
	double	*TimesArray;

	double		**DzDts;
	VectorCache BzDtCache;

	ConductiveLayer *Layers;
	int				NumLayers;

	double			MaxAnalT;

	bool			NeedRecalc;
	
	static const InfoM  InfosM[11];


private:
	
	inline double BesselInt(double iF1, double iF2, double iR, double iX0, double iX1);
	inline double IntFunction(int iMsIndex, int iTimeIndex);
	bool CreateDzDt(double iZ);
	void TimeInterpolation(vector<double> &iFrom, double *oTo, double *iTimes, int iTimeCnt);
	double AnalDbzDt(double iT, double iR);


public:
	VertMagnDipole();

	void SetMedium(ConductiveLayer *iLayers, int iNumLayers);

	bool Br(double iR, double iZ, double *oResV, double *iTimes, int iTimeCount);
	bool Bz(double iR, double iZ, double *oResV, double *iTimes, int iTimeCount);

	bool Ephi(double iR, double iZ, double *oResV, double *iTimes, int iTimeCount);


	bool DBrDt(double iR, double iZ, double *oResV, double *iTimes, int iTimeCount);
	bool DBzDt(double iR, double iZ, double *oResV, double *iTimes, int iTimeCount);

	bool DEphiDt(double iR, double iZ, double *oResV, double *iTimes, int iTimeCount);

	~VertMagnDipole();
};
